package calvin.study.rabbitmq.advanced.limit;

import java.io.IOException;

import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

public class CustomConsumer extends DefaultConsumer {
	
	private Channel channel;

	public CustomConsumer(Channel channel) {
		super(channel);
		this.channel = channel;
	}

	@Override
	public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body)
			throws IOException {
		System.out.println("消费者2接收消息：" + new String(body));
//		System.err.println("-----------consume message----------");
//		//消费标签
//		System.err.println("consumerTag: " + consumerTag);
//		System.err.println("envelope: " + envelope);
//		System.err.println("properties: " + properties);
//		System.err.println("body: " + new String(body));
		//手工签收
		channel.basicAck(envelope.getDeliveryTag(), false);
//		try {
//			Thread.sleep(500);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
	}

}
